//var inte = "";	//定时器

//$(document).keypress(function (e) {
//    var event = arguments.callee.caller.arguments[0] || window.event;//消除浏览器差异  
//    if (event.keyCode == 13) {
//        login();
//    }
//})
//$("#to-recover").bind("click", login);

window.onload = checkislogin;

function checkislogin()
{
//		url = "ajaxlist.php";
//		var username = $('input[name="username"]').val();
//		var passwd = $('input[name="password"]').val();
//		var savepwdStatus = $('input[name="savepwd"]').attr("checked");
//		act = 'login';
//		$.ajax({
//			url:url,
//			type:'POST',
//			data:{act:act,username:username,passwd:passwd,savepwd:savepwdStatus},
//			dataType:"json",
//			success:function(text)
//			{
//				if(text.status == 1)
//				{
//					location.href = text.url;				
//				}
//				else
//				{
//					$('#errmsg').html('<font color="red">帐号或密码错误</font>');
//					$('#errmsg').show();
//					
//					inte = setInterval("hidemsg()",3000);
//				}
//			}
//		})	
    var sign = $("#sign").val();
    var time = $("#time").val();
    var system = $("#system").val();
    var goto_url = $("#goto_url").val();
    var url = $("#oauth_check_url").val();
    var oauth_login_url = $("#oauth_login_url").val();
   
    $.ajax({
        type: "get",
        async: false,
        url: url,
        data: {ranNum: Math.random(), sign: sign, time: time, system: system},
        dataType: "jsonp", //数据类型为jsonp  
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (data) {
            var user_name = "";      //登陆名
            var buss_user_name = ""; //业务用户名
            var system = "";         //系统名
            var code = "";           //登陆状态标识
            var sessid = "";         //sessionID
            var myobj = eval("[" + data.result + "]");
            for (var i = 0; i < myobj.length; i++) {
                user_name = myobj[i].user.user_name;
                buss_user_name = myobj[i].user.buss_user_name;
                sessid = myobj[i].user.sessid;
                system = myobj[i].user.system;
                code = myobj[i].code;
            }

            if (code == -1) {
                //未登录，跳到登陆页面
                //alert(oauth_login_url + "?goto_url=" + goto_url);
                window.location.href = oauth_login_url + "?goto_url=" + goto_url;
            } else if (code == 1) {
                //已登录，进行模拟登陆
                window.location.href = goto_url + "/authLogin.php?user_name=" + user_name + "&time=" + time + "&sign=" + sign + "&system=" + system + "&goto_url=" + goto_url + "&sessid=" + sessid;
            } else if (code == 2) {
                alert("用户未与该业务系统绑定!");
            } else if (code == 3) {
                alert("密钥错误!");
            }
        },
        error: function () {
            alert('请求错误！');
        }
    });
}
